package com.huawei.appmarket.service.appdetail.view.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.widget.BounceViewPager;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol.Request;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.ayw;
import o.cgv;
import o.Logger;
import o.CollectCheck;
import o.eqw;
import o.MinimumFactory;
import o.evd;
import o.ewm.c;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.PagerAdapter;

public class GalleryActivity extends BaseActivity<GalleryActivityProtocol> implements OnPageChangeListener, OnClickListener {
    private boolean ˊॱ = false;
    private int ˋॱ = -1;
    private ImageView[] ˏॱ;
    private BounceViewPager ͺ = null;
    private List<String> ॱˊ = null;
    private boolean ॱˋ;
    private List<Boolean> ॱˎ;
    private d ᐝॱ = null;

    public class d extends PagerAdapter {
        private Context ˊ = null;
        final /* synthetic */ GalleryActivity ˋ;
        private List<View> ˎ = new ArrayList();

        protected d(GalleryActivity galleryActivity, Context context) {
            this.ˋ = galleryActivity;
            this.ˊ = context;
        }

        public Object instantiateItem(ViewGroup viewGroup, int i) {
            String ˏ = ˏ(i);
            View imageView = new ImageView(this.ˊ);
            this.ˎ.add(imageView);
            viewGroup.addView(imageView);
            try {
                if (this.ˋ.ॱˋ) {
                    eqw.ˎ(imageView, ˏ, ॱ(i));
                } else {
                    eqw.ˎ(imageView, ˏ, this.ˋ.ˊॱ);
                }
            } catch (NumberFormatException e) {
                Logger.ˋ("GalleryActivity", "instantiateItem error, Exception: NumberFormatException, url:" + ˏ);
            } catch (OutOfMemoryError e2) {
                Logger.e("GalleryActivity", "instantiateItem error, Exception: OutOfMemoryError, url:" + ˏ);
            }
            return imageView;
        }

        public String ˏ(int i) {
            if (i < getCount()) {
                return (String) this.ˋ.ॱˊ.get(i);
            }
            return null;
        }

        public boolean ॱ(int i) {
            if (i < getCount()) {
                return ((Boolean) this.ˋ.ॱˎ.get(i)).booleanValue();
            }
            return false;
        }

        public int getCount() {
            return this.ˋ.ॱˊ.size();
        }

        public void destroyItem(ViewGroup viewGroup, int i, Object obj) {
            View view = (View) obj;
            viewGroup.removeView(view);
            this.ˋ.ˋ(view);
            this.ˎ.remove(view);
        }

        public boolean isViewFromObject(View view, Object obj) {
            return view == obj;
        }

        public int getItemPosition(Object obj) {
            return -2;
        }
    }

    public void onCreate(Bundle bundle) {
        requestWindowFeature(1);
        super.onCreate(bundle);
        getWindow().addFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        cgv.ˋ(this, c.ʽॱ, c.ʽॱ);
        if (evd.ˎ()) {
            evd.ˊ(getWindow(), 1);
        }
        GalleryActivityProtocol galleryActivityProtocol = (GalleryActivityProtocol) ʾ();
        if (galleryActivityProtocol == null) {
            finish();
            return;
        }
        Request ˊ = galleryActivityProtocol.ˊ();
        if (ˊ == null) {
            finish();
            return;
        }
        this.ॱˊ = ˊ.ˏ();
        if (CollectCheck.isEmpty(this.ॱˊ)) {
            finish();
            return;
        }
        boolean z;
        this.ˋॱ = ˊ.ˋ();
        if (this.ˋॱ < 0 || this.ˋॱ >= this.ॱˊ.size()) {
            this.ˋॱ = 0;
        }
        if (MinimumFactory.getBoolValue(this)) {
            try {
                Collections.reverse(this.ॱˊ);
            } catch (UnsupportedOperationException e) {
                Logger.e("GalleryActivity", "reverse list error");
            }
            this.ˋॱ = (this.ॱˊ.size() - 1) - this.ˋॱ;
        }
        this.ˊॱ = ˊ.ˊ();
        this.ॱˎ = ˊ.ˎ();
        if (this.ॱˎ == null || this.ॱˎ.isEmpty()) {
            z = false;
        } else {
            z = true;
        }
        this.ॱˋ = z;
        setContentView(h.ॱ);
        ayw.ˋ(this, findViewById(j.ﾟᐝ), null, true);
        ᐝ();
    }

    private void ᐝ() {
        ViewGroup viewGroup = (ViewGroup) findViewById(j.ˆॱ);
        this.ˏॱ = new ImageView[this.ॱˊ.size()];
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
        for (int i = 0; i < this.ˏॱ.length; i++) {
            this.ˏॱ[i] = new ImageView(this);
            if (i == this.ˋॱ) {
                this.ˏॱ[i].setImageDrawable(getResources().getDrawable(e.ॱˎ));
            } else {
                this.ˏॱ[i].setImageDrawable(getResources().getDrawable(e.ʻॱ));
            }
            if (i < this.ˏॱ.length - 1) {
                layoutParams.setMarginStart((int) getResources().getDimension(o.ewm.d.ˍ));
            }
            this.ˏॱ[i].setLayoutParams(layoutParams);
            viewGroup.addView(this.ˏॱ[i]);
        }
        this.ͺ = (BounceViewPager) findViewById(j.ﾟˋ);
        this.ᐝॱ = new d(this, this);
        this.ͺ.setPageCount(this.ॱˊ.size());
        this.ͺ.setAdapter(this.ᐝॱ);
        this.ͺ.setCurrentItem(this.ˋॱ);
        this.ͺ.setOnPageChangeListener(this);
    }

    public void onPageScrollStateChanged(int i) {
        this.ˏॱ[i].setImageDrawable(getResources().getDrawable(e.ॱˎ));
        this.ˏॱ[this.ˋॱ].setImageDrawable(getResources().getDrawable(e.ʻॱ));
        this.ˋॱ = i;
    }

    public void onPageScrolled(int i) {
    }

    public void onPageScrolled(int i, float f, int i2) {
    }

    public void onClick(View view) {
        finish();
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.ॱˊ != null) {
            this.ॱˊ.clear();
        }
    }

    private void ˋ(View view) {
        if (view instanceof ImageView) {
            try {
                Drawable drawable = ((ImageView) view).getDrawable();
                if (drawable != null && (drawable instanceof BitmapDrawable)) {
                    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                    if (bitmap != null && bitmap.isRecycled()) {
                    }
                }
            } catch (IllegalArgumentException e) {
                Logger.ˎ("GalleryActivity", "bitmap.recycle() , IllegalArgumentException e : " + e.toString());
            }
        }
    }
}
